from django.contrib.auth.models import Group
from apps.meiduo_admin.serialziers.groups import GroupsSerializer
from rest_framework.decorators import action
from rest_framework.viewsets import ModelViewSet
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from apps.meiduo_admin.utils import NumPage
from apps.users.models import User
from apps.meiduo_admin.serialziers.users import UserSerializer


class AdminsView(ModelViewSet):
    # 指定查询集
    queryset = User.objects.filter(is_staff=True)
    # 指定序列化器
    serializer_class = UserSerializer
    # 指定权限
    permission_classes = [IsAdminUser]
    # 指定分页
    pagination_class = NumPage

    # # 获取简单权限
    def simple(self, request):
        # 获取所有权限
        perms = Group.objects.all()
        # 返回权限
        ser = GroupsSerializer(perms, many=True)
        return Response(ser.data)